#region Imported Namespaces
using System;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

using BO					= PHSRAG.Insight21.BusinessObjects;
using DataAccess			= PHSRAG.Utility.DataAccess;
using ICachePolicy			= PHSRAG.Insight21.Policy.ICachePolicy;
using AgreementConstants	= PHSRAG.Insight21.Agreements.AgreementConstants;
using GenerateKey = PHSRAG.Insight21.BusinessObjects.ModuleKey;
#endregion

namespace PHSRAG.Insight21.Agreements
{
	/// <summary>
	/// The SalaryDistribution class is the facade over the details for a single 
	/// Salary Distribution information.
	/// </summary>
	public class SalaryDistribution : BO.BusinessObject
	{
		#region Constants
		private static string SalaryDistributionKey = GenerateKey.MakeKey("SalaryDistribution_8DF9F04D-1DAB-4675-87FF-445C9D62FEAC",GenerateKey.Agreement);
		#endregion

		#region Instance Variables
		private DataRow	dataRow;
		#endregion

		#region Constructor
		/// <summary>
		/// Initialize the base class with the specified cache policy, and save the DataRow in this instance.
		/// This is an example of a scenario where even though the SalaryDistribution IS a business object, it DOES NOT
		/// use the DataContainer to store anything. The DataContainer is typically used when the BusinessObject is itself
		/// responsibly for loading the data for which it is the facacde. However, we have a scenario where the data for
		/// this object is already loaded (by the SalaryDistributions object), and the Salary Distribution object simply
		/// provides the facade.
		/// </summary>
		/// <param name="cachePolicy">Prevalent cache policy</param>
		/// <param name="row">DataRow for the facade</param>
		public SalaryDistribution(ICachePolicy cachePolicy, DataRow row) : base(cachePolicy)
		{
			dataRow = row;
		}
		#endregion

		#region Business Object Methods
		/// <summary>
		/// This method is not used and only exists to satisfy interface requirements.
		/// throws exception if UI tries to call this method.
		/// </summary>
		public override void Load(string connectionString, params object[] args) 
		{
			throw new Exception("Salary Distribution is not directly loadable");
		}

		/// <summary>
		/// Puts this instance to session using the cache policy identified using Salary DistributionKey
		/// </summary>
		public override void Cache() 
		{
			CachePolicy.Cache(SalaryDistributionKey, this);
		}

		/// <summary>
		/// Removes the object from the session using the cache policy identified using Salary DistributionKey
		/// </summary>
		public override void UnCache() 
		{
			CachePolicy.UnCache(SalaryDistributionKey);
		}
		#endregion

		#region Public Properties
		
		/// <summary>
		/// Gets employees last name from the data container.
		/// </summary>
		public string LastName 
		{
			get
			{
				object o = dataRow[AgreementConstants.LastName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Gets employees first name from the data container.
		/// </summary>
		public string FirstName 
		{
			get
			{
				object o = dataRow[AgreementConstants.FirstName];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}
		/// <summary>
		/// Gets fundnumber from the data container.
		/// </summary>
		public string FundNumber 
		{
			get
			{
				object o = dataRow[AgreementConstants.FundNumber];
				return (o == DBNull.Value) ? string.Empty : (string)o;
			}
		}

		/// <summary>
		/// Gets employee's annual rate from the data container. 
		/// </summary>
		public decimal AnnualRate 
		{
			get
			{
				object o = dataRow[AgreementConstants.AnnualRate];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee's start date from the data container. 
		/// </summary>
		public string StartDate 
		{
			get
			{
				object o = dataRow[AgreementConstants.StartDate];
				return (o == DBNull.Value) ? string.Empty : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}

		/// <summary>
		/// Gets employee's end date from the data container.
		/// </summary>
		public string EndDate 
		{
			get
			{
				object o = dataRow[AgreementConstants.EndDate];
				return (o == DBNull.Value) ? string.Empty : ((DateTime)o).ToString("MM/dd/yyyy");
			}
		}

		/// <summary>
		/// Gets employee's monthly rate from the data container.
		/// </summary>
		public decimal MonthlyRate 
		{
			get
			{
				object o = dataRow[AgreementConstants.MonthlyRate];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee's months remaining from the data container.
		/// </summary>
		public decimal MonthsRemaining 
		{
			get
			{
				object o = dataRow[AgreementConstants.MonthsRemaining];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee's committed salary from the data container.
		/// </summary>
		public decimal CommittedSalary 
		{
			get
			{
				object o = dataRow[AgreementConstants.CommittedSalary];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee's fringe rate from the data container.
		/// </summary>
		public decimal FringeRate 
		{
			get
			{
				object o = dataRow[AgreementConstants.FringeRate];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee committed fringe amount from the data container. 
		/// </summary>
		public decimal CommittedFringe 
		{
			get
			{
				object o = dataRow[AgreementConstants.CommittedFringe];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee total committed amount from the data container. 
		/// </summary>
		public decimal TotalCommitted 
		{
			get
			{
				object o = dataRow[AgreementConstants.TotalCommitted];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee paid to date amount from the data container. 
		/// </summary>
		public decimal PaidToDate 
		{
			get
			{
				object o = dataRow[AgreementConstants.PaidToDate];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee planned percentage effort from the data container. 
		/// </summary>
		public decimal TrackedEffort 
		{
			get
			{
				object o = dataRow[AgreementConstants.TrackedEffort];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Gets employee actual percentage sponsor effort from the data container. 
		/// </summary>
		public decimal SponsorEffort 
		{
			get
			{
				object o = dataRow[AgreementConstants.SponsorEffort];
				return (o == DBNull.Value) ? 0 : Convert.ToDecimal(o);
			}
		}

		/// <summary>
		/// Get the PerEmployeeJobMapId.
		/// </summary>
		public int PerEmployeeJobMapId
		{
			get 
			{
				object o = dataRow["PerEmployeeJobMapId"];
				return (o == DBNull.Value) ? 0 : (int)o;
			}
		}

		#endregion
	}
}
